﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;

namespace WRSManagementSystem.Model.Repos
{
    public interface IRepository<T>
    {
        /// <summary>
        /// Returns a count of the items in the repository
        /// </summary>
        int Count();

        /// <summary>
        /// Returns a count of the items in the repository which match the supplied lambda
        /// </summary>
        /// <param name="expression">A lambda expression which will be evaluated against the repository</param>
        int Count(Expression<Func<T, bool>> expression);

        /// <summary>
        /// Adds a new entity in to the repository
        /// </summary>
        void Add(T entity);

        /// <summary>
        /// Removes the specified entity from the repository
        /// </summary>
        void Remove(T entity);

        /// <summary>
        /// Saves the specified entity back to the repository
        /// </summary>
        void Save(T entity);

        /// <summary>
        /// Finds a single instance of an entity matching a unique identifier.
        /// </summary>
        T FindOne(Guid id);

        /// <summary>
        /// Finds a single instance of an entity matching a lambda expression
        /// </summary>
        /// <returns>The first entity which matches the expession</returns>
        T FindOne(Expression<Func<T, bool>> expression);

        /// <summary>
        /// Tries the find one.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        bool TryFindOne(Expression<Func<T, bool>> expression, out T entity);       

        /// <summary>
        /// Returns a requeryable set of all entities in the repository
        /// </summary>
        IQueryable<T> Find();

        /// <summary>
        /// Returns a requeryable set of all entities in the repository matching a unique identifier
        /// </summary>
        IQueryable<T> Find(Guid id);

        /// <summary>
        /// Returns a requeryable set of all entities in the repository matching a lambda expression
        /// </summary>
        IQueryable<T> Find(Expression<Func<T, bool>> expression);
    }
}
